<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class CarBrand extends Model
{

    /**
     * 关联到模型的数据表
     *
     * @var string
     */
    protected $table = 'car_brand';

    public static function brand( $id ){

        $sql = "select * from car_brand where id=?";
        $data = DB::select( $sql, [ $id ] );
        return !empty( $data ) ? $data[0] : '';

    }

    public static function brands( $data ){

        $where = " where 1=1 ";
        if( !empty($data['name']) ){
            $where .= " and name like " . "'%".$data['name'] ."%'";
        }
        if( !empty($data['letter_pre']) ){
            $where .= " and letter_pre like " . "'%".$data['letter_pre'] ."%'";
        }

        $sql = "select * from car_brand" . $where;
        $data = DB::select( $sql );
        return $data;

    }



}